<?php

// +----------------------------------------------------------------------
// | ADM Software [ 我宁可 为做过的事而后悔，也不想 因为没尝试而后悔。 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 扬州安蝶梦电子商务有限公司 All rights reserved.
// +----------------------------------------------------------------------
// | Author: 曹梦龙 <138888611@qq.com> <http://www.andiemeng.com>
// +----------------------------------------------------------------------

namespace Org\BMap;

class Bounds {

    public $minLng;
    public $minLat;
    public $maxLng;
    public $maxLat;

    function __construct($PointArray) {
        foreach ($PointArray as $key => $pt) {
            //echo $key . "=>" . $pt->lat . "\n";
            if(!$this->minLng){
                $this->minLng=$pt->lng;
            }else{
               if($pt->lng < $this->minLng) {
                   $this->minLng=$pt->lng;
               }
            }
            if(!$this->minLat){
                $this->minLat=$pt->lat;
            }else{
               if($pt->lat < $this->minLat) {
                 $this->minLat=$pt->lat;
               } 
            }
            if(!$this->maxLng){
                $this->maxLng=$pt->lng;
            }else{
                if($pt->lng > $this->maxLng) {
                 $this->maxLng=$pt->lng;
               } 
            }
            if(!$this->maxLat){
                $this->maxLat=$pt->lat;
            }else{
                 if($pt->lat > $this->maxLat) {
                 $this->maxLat=$pt->lat;
               } 
            }
        }
    }

    function isPointInRect($point){
        if($this->minLng <= $point->lng && $point->lng <=$this->maxLng && $this->minLat <= $point->lat && $point->lat<= $this->maxLat){
            return TRUE;
        }else{
            return FALSE;
        }
    }
}
